<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>其它类型的promise封装</title>
  </head>
  <body></body>
  <script>
    //返回一个新的promise对象
    let p1 = new Promise((resolve, reject) => {
      resolve("fulfilled");
    })
      .then(
        (value) => {
          return new Promise((resolve, reject) => {
            resolve("成功");
          });
        },
        (reason) => {}
      )
      .then((value) => {
        console.log(value);
      });
    //返回一个类，里面有then方法
    let p2 = new Promise((resolve, reject) => {
      resolve("fulfilled");
    })
      .then(
        (value) => {
          class Hd {
            then(resolve, reject) {
              setTimeout(() => {
                resolve("这是对象");
              }, 2000);
            }
          }
          return new Hd();
        },
        (reason) => {}
      )
      .then((value) => {
        console.log(value);
      });
  </script>
</html>
